home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / iff / plopsound3.c < prev    next >
C/C++ Source or Header  |  1987-02-15  |  10KB  |  506 lines

  1. #include    <exec/types.h>
  2. #include        <exec/memory.h> /* soundprod */
  3.  
  4. #include    <graphics/gfx.h>
  5. #include        <graphics/sprite.h> /* voor sprites */
  6. #include    <intuition/intuition.h>
  7. #include     <stdio.h> /* ook voor soundprod */
  8. #include     "df1:iff/jiff.c"
  9.  
  10. #include "hardware/custom.h" /* soundprod */
  11.  
  12.  
  13. #define FRAMES        6
  14. #define SPRHEIGHT    16
  15. #define WORDSPERSPR    (2 * SPRHEIGHT + 4)
  16. #define MAXX        (XMAX-32)
  17. #define MAXY        (YMAX-16)
  18.  
  19. extern UWORD    ballmask[], ball0[];
  20. extern long    GetSprite();
  21.  
  22. UBYTE        idx[] = { 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4 };
  23. struct SimpleSprite    spr[FRAMES];
  24. UWORD        *sprbuf;
  25. UWORD        *sprites[FRAMES];
  26. int        vx[FRAMES], vy[FRAMES];
  27.  
  28.  
  29.  
  30. LONG filesize,s1,s2,per;
  31. char *filename;
  32. short *sndbuffer;
  33.  
  34.  
  35. /*This should be in exec/libraries.h */
  36. extern struct Library *OpenLibrary();
  37.  
  38. /*This should be in intuition/intuition.h */
  39. extern struct Screen *OpenScreen();
  40.  
  41. /* These are the bases for the libraries you need to do any graphics
  42.    much at all and still multi-task */
  43. struct Library *GfxBase = NULL;
  44. struct Library *LayersBase = NULL;
  45. struct Library    *IntuitionBase = NULL;
  46.  
  47. /* Well the workbench Screen isn't 320x200x5 so...*/
  48. struct Screen *PlopScreen = NULL;
  49.  
  50. /* Just one font for me... not static cause you might want it
  51.    in your menu modules. */
  52. struct TextAttr PlopFont =
  53.     {
  54.     "topaz.font",  /* I think this is the ROM font */
  55.     8,
  56.     0,
  57.     0,
  58.     };
  59.  
  60. /* a NewScreen - I don't know what half of this means either */
  61. static
  62. struct NewScreen PlopNewScreen =
  63.     {
  64.     0, 0, XMAX, YMAX, PLANES,
  65.     0, 1,
  66.     0,
  67.     CUSTOMSCREEN,
  68.     &PlopFont,
  69.     "Plop on Top",
  70.     NULL,
  71.     NULL,
  72.     };
  73.  
  74. /* To use clip blit need a RastPort.  Pretty useless, a BitMap should
  75.    be enough I think ... or anyway something a little less massive */
  76. struct RastPort PlopRastPort;
  77. struct ViewPort *vp;
  78.  
  79. void
  80. put_ea_cmap(cmap, colors)
  81. unsigned char *cmap;
  82. long colors;
  83. {
  84. long i;
  85. unsigned long r, g, b;
  86.  
  87. if (colors > 32)    /*color clipping*/
  88.     colors = 32;
  89.  
  90. /* This loop is modified to work with Aztec 3.4a 32bit by J. Van Houtven */
  91. /* Modification Date : 20 July 1987 */
  92.  
  93. for (i=0; i<colors; i++)
  94.     {
  95.          r= *cmap++ >> 4;
  96.          g= *cmap++ >> 4;
  97.          b= *cmap++ >> 4;
  98.          SetRGB4(&PlopScreen->ViewPort,i,(long)r,(long)g,(long)b);
  99.     }
  100. }
  101.  
  102.  
  103. main(argc, argv)
  104. int argc;
  105. char *argv[];
  106. {
  107. int i,j,x,y,offset = 0, flag = 0, speed;
  108. struct ILBM_info *info;
  109.  
  110. /* aanroep van sound routine */
  111.  
  112. custom.dmacon = 0x0003;
  113. per = 280;
  114. filename = "TAON_1";
  115. filesize = 42676;
  116. MakeSound();
  117.  
  118.  
  119. if ((GfxBase =  OpenLibrary("graphics.library", (long)0)) == NULL)
  120.         return(-1);
  121.  
  122. if ((LayersBase =  OpenLibrary("layers.library", (long)0)) == NULL)
  123.     {
  124.     plop_cleanup();
  125.     return(-2);
  126.     }
  127.  
  128. if ((IntuitionBase =  OpenLibrary("intuition.library",(long) 0)) == NULL)
  129.     {
  130.     plop_cleanup();
  131.     return(-3);
  132.     }
  133.  
  134. if ( (PlopScreen = OpenScreen(&PlopNewScreen) ) == NULL)
  135.     {
  136.     plop_cleanup();
  137.     return(-4);
  138.     }
  139. vp = &(PlopScreen->ViewPort);
  140.  
  141. InitRastPort(&PlopRastPort);
  142. PlopRastPort.Mask = (1<<PLANES)-1;
  143. /*just play it safe in case someone tries to load 6 bit planes...*/
  144.  
  145. setupsprites ();
  146.  
  147.  
  148. for (x=1; x<argc; x++)
  149. {
  150.  if ( (info = read_iff(argv[x], 0) ) != NULL)
  151.  {
  152.   put_ea_cmap(&info->cmap, (1 << info->bitmap.Depth));
  153.   PlopRastPort.BitMap = &info->bitmap;
  154.   ClipBlit( &PlopRastPort, (long)0, (long)0,
  155.            &PlopScreen->RastPort, (long)info->header.x, (long)info->header.y,
  156.        (long)info->header.w, (long)info->header.h, (long)COPY_MINTERM);
  157.  
  158.  for (i=0; i<FRAMES; i++)
  159.  {
  160.     if (GetSprite (&spr[i], (long) i+2) < 0)
  161.             plop_cleanup();
  162.     spr[i].x = 16*i;
  163.     spr[i].y = 16*i;
  164.     spr[i].height = SPRHEIGHT;
  165.     ChangeSprite (vp, &spr[i], sprites[i]);
  166.  }
  167.  speed = 4;
  168.  
  169.  for (i=0; i<FRAMES; i++)
  170.  {
  171.   vx[i]= vy[i]=speed;
  172.  }
  173.  
  174.  --speed;
  175.  
  176.  for(j=0;j<1000;j++)
  177.  {
  178.   WaitTOF ();
  179.   for (i=0; i<FRAMES; i++)
  180.   {
  181.    if((spr[i].x += vx[i]) >= MAXX-speed || spr[i].x <= speed)
  182.    {
  183.     vx[i] = -vx[i];
  184.    }
  185.  
  186.    if((spr[i].y += vy[i]) >= MAXY-speed || spr[i].y <= speed)
  187.    { 
  188.     vy[i] = -vy[i];
  189.    }
  190.   }
  191.  
  192.   /* Hey !!! ChangeSprite also MOVES the sprites !!!! */
  193.   for (i=0; i<FRAMES; i++) ChangeSprite (vp, &spr[i], sprites[idx[i+offset]]);
  194.  
  195.    /*  Rotate balls every other loop  */
  196.   if (flag = !flag) offset = (offset + 1) % 6;
  197.  
  198.  }
  199.  
  200.   /* scherm schuin */
  201.  
  202.   y = YMAX-1;
  203.   for(j=0;j<80;j++)
  204.   {
  205.    i=j<<2;
  206.    ScrollRaster(&PlopScreen->RastPort,0L,j-40L,i,0L,i+3L,y);
  207.   }
  208.  
  209.  for(j=0;j<1000;j++)
  210.  {
  211.   WaitTOF ();
  212.   for (i=0; i<FRAMES; i++)
  213.   {
  214.    if((spr[i].x += vx[i]) >= MAXX-speed || spr[i].x <= speed)
  215.    {
  216.     vx[i] = -vx[i];
  217.    }
  218.  
  219.    if((spr[i].y += vy[i]) >= MAXY-speed || spr[i].y <= speed)
  220.    { 
  221.     vy[i] = -vy[i];
  222.    }
  223.   }
  224.  
  225.   /* Hey !!! ChangeSprite also MOVES the sprites !!!! */
  226.   for (i=0; i<FRAMES; i++) ChangeSprite (vp, &spr[i], sprites[idx[i+offset]]);
  227.  
  228.    /*  Rotate balls every other loop  */
  229.   if (flag = !flag) offset = (offset + 1) % 6;
  230.  
  231.  }
  232.    /* cleanup sprites */
  233.   
  234.   for (i=0; i<FRAMES; i++)
  235.     if (spr[i].num) FreeSprite ((long) spr[i].num);
  236.  
  237.  
  238.  
  239.   SetAPen(&PlopScreen->RastPort,0);
  240.   for(j=0;j<100;j++)
  241.   {
  242.    Move(&PlopScreen->RastPort,0,j);Draw(&PlopScreen->RastPort,XMAX-1,j);
  243.    Move(&PlopScreen->RastPort,0,YMAX-1-j);Draw(&PlopScreen->RastPort,XMAX-1,YMAX-1-j);
  244.   }
  245.  
  246.   free_planes(&info->bitmap);
  247.   }
  248.  }
  249. plop_cleanup();
  250. }
  251. /* ====== end of main ======= */
  252.  
  253. plop_cleanup()
  254. {
  255. register int i;
  256.  
  257. custom.dmacon = 0x0003;
  258. if(sndbuffer)
  259.         FreeMem(sndbuffer,filesize);
  260.  
  261. for (i=0; i<FRAMES; i++)
  262.   if (spr[i].num) FreeSprite ((long) spr[i].num);
  263.  
  264. if (sprbuf)
  265.     FreeMem (sprbuf, 2L * WORDSPERSPR * FRAMES);
  266. if (PlopScreen != NULL)
  267.     CloseScreen(PlopScreen);
  268. if (IntuitionBase != NULL)
  269.     CloseLibrary(IntuitionBase);
  270. if (LayersBase != NULL)
  271.     CloseLibrary(LayersBase);
  272. if (GfxBase != NULL)
  273.     CloseLibrary(GfxBase);
  274. }
  275.  
  276.  
  277. MakeSound()
  278. {
  279. LoadSound();
  280. PlaySong();
  281. }  
  282.  
  283. LoadSound()
  284. {
  285. FILE *fopen(), *fp;
  286. SHORT *ptr;
  287. LONG i;
  288.  
  289. sndbuffer = AllocMem(filesize,MEMF_CHIP);
  290. ptr = sndbuffer;
  291.  
  292. custom . dmacon = 0x0003;
  293. fp = fopen(filename,"r");
  294. if (fp == NULL) return(0);
  295.  
  296. s1 = 0; s2 =filesize;
  297. for (i=0; i<s1; i++)
  298.     getc(fp);
  299.  
  300. for (i=s1/2; i<s2/2; i++)
  301.     {
  302.     *ptr++ = getc(fp)*256 + getc(fp);
  303.     }
  304.  
  305. fclose (fp);
  306. }
  307.  
  308. PlaySong()
  309. {
  310. custom . aud[0].ac_ptr = (UWORD *)sndbuffer;
  311. custom . aud[0].ac_len = s2/2-s1/2;
  312. custom . aud[0].ac_per = per;
  313. custom . aud[0].ac_vol = 64;
  314.  
  315. custom . aud[1].ac_ptr = (UWORD *)sndbuffer;
  316. custom . aud[1].ac_len = s2/2-s1/2;
  317. custom . aud[1].ac_per = per;
  318. custom . aud[1].ac_vol = 64;
  319.  
  320. custom . dmacon = 0x8203;
  321. }
  322.  
  323. setupsprites ()
  324. {
  325.     UWORD *cw;    /* current position in buffer of sprite images */
  326.     UWORD *maskp;    /* current position in ballmask             */
  327.     UWORD *ballp;    /* current position in ball0 data           */
  328.     int frame, scan;
  329.  
  330.     if (!(sprbuf = AllocMem (2L * WORDSPERSPR * FRAMES, MEMF_CHIP)))
  331.         plop_cleanup();
  332.  
  333.     cw = sprbuf;    /* current position at top of buffer */
  334.     ballp = ball0;    /* ... top of data to be interleaved */
  335.  
  336.     for (frame=0; frame<FRAMES; frame++) {
  337.         maskp = ballmask;    /* one mask for all frames */
  338.         sprites[frame] = cw;
  339.         *cw++ = 0;        /* poscntl */
  340.         *cw++ = 0;
  341.  
  342.         /* one word from ball0, one word from ballmask */
  343.         for (scan=0; scan<SPRHEIGHT; scan++) {
  344.             *cw++ = *maskp++;
  345.             *cw++ = *ballp++;
  346.         }
  347.         *cw++ = 0;    /* termination */
  348.         *cw++ = 0;
  349.     }
  350. }
  351.  
  352. #asm
  353. *:ts=8 bk=0
  354. _ballmask:
  355.     public    _ballmask
  356.  
  357.     dc.w    %0000011111100000
  358.     dc.w    %0001111111111000
  359.     dc.w    %0011111111111100
  360.     dc.w    %0111111111111110
  361.     dc.w    %0111111111111110
  362.     dc.w    %1111111111111111
  363.     dc.w    %1111111111111111
  364.     dc.w    %1111111111111111
  365.     dc.w    %1111111111111111
  366.     dc.w    %1111111111111111
  367.     dc.w    %1111111111111111
  368.     dc.w    %0111111111111110
  369.     dc.w    %0111111111111110
  370.     dc.w    %0011111111111100
  371.     dc.w    %0001111111111000
  372.     dc.w    %0000011111100000
  373.  
  374.  
  375. _ball0:
  376.     public    _ball0
  377.  
  378.     dc.w    %0000011001100000
  379.     dc.w    %0001100110011000
  380.     dc.w    %0011001111001100
  381.     dc.w    %0001110000111000
  382.     dc.w    %0011110000111100
  383.     dc.w    %0011100000011100
  384.     dc.w    %1100011111100011
  385.     dc.w    %1000011111100001
  386.     dc.w    %1000011111100001
  387.     dc.w    %1100011111100011
  388.     dc.w    %0011100000011100
  389.     dc.w    %0011110000111100
  390.     dc.w    %0001110000111000
  391.     dc.w    %0011001111001100
  392.     dc.w    %0001100110011000
  393.     dc.w    %0000011001100000
  394.  
  395.  
  396. _ball1:
  397.     public    _ball1
  398.  
  399.     dc.w    %0000010011000000
  400.     dc.w    %0001001100110000
  401.     dc.w    %0010011100011000
  402.     dc.w    %0001100001110010
  403.     dc.w    %0011100001111010
  404.     dc.w    %0111000001111001
  405.     dc.w    %1000111110000111
  406.     dc.w    %1000111110000011
  407.     dc.w    %1000111110000011
  408.     dc.w    %1000111110000111
  409.     dc.w    %0111000001111001
  410.     dc.w    %0011100001111010
  411.     dc.w    %0001100001110010
  412.     dc.w    %0010011100011000
  413.     dc.w    %0001001100110000
  414.     dc.w    %0000010011000000
  415.  
  416.  
  417. _ball2:
  418.     public    _ball2
  419.  
  420.     dc.w    %0000010011000000
  421.     dc.w    %0001001100110000
  422.     dc.w    %0000011000011000
  423.     dc.w    %0011000111100110
  424.     dc.w    %0010000111100010
  425.     dc.w    %0110000111110001
  426.     dc.w    %0001111000001110
  427.     dc.w    %0011111000001110
  428.     dc.w    %0011111000001110
  429.     dc.w    %0001111000001110
  430.     dc.w    %0110000111110001
  431.     dc.w    %0010000111100010
  432.     dc.w    %0011000111100110
  433.     dc.w    %0000011000011000
  434.     dc.w    %0001001100110000
  435.     dc.w    %0000010011000000
  436.  
  437.  
  438. _ball3:
  439.     public    _ball3
  440.  
  441.     dc.w    %0000000110000000
  442.     dc.w    %0000011001100000
  443.     dc.w    %0000110000110000
  444.     dc.w    %0110001111000110
  445.     dc.w    %0110001111000110
  446.     dc.w    %1100011111100011
  447.     dc.w    %0011100000011100
  448.     dc.w    %0111100000011110
  449.     dc.w    %0111100000011110
  450.     dc.w    %0011100000011100
  451.     dc.w    %1100011111100011
  452.     dc.w    %0100001111000010
  453.     dc.w    %0110001111000110
  454.     dc.w    %0000110000110000
  455.     dc.w    %0000011001100000
  456.     dc.w    %0000000110000000
  457.  
  458.  
  459. _ball4:        ; Batter takes first base
  460.     public    _ball4
  461.  
  462.     dc.w    %0000001100100000
  463.     dc.w    %0000110011001000
  464.     dc.w    %0001100001100000
  465.     dc.w    %0110011110001100
  466.     dc.w    %0100011110000100
  467.     dc.w    %1000111110000110
  468.     dc.w    %0111000001111000
  469.     dc.w    %0111000001111100
  470.     dc.w    %0111000001111100
  471.     dc.w    %0111000001111000
  472.     dc.w    %1000111110000110
  473.     dc.w    %0100011110000100
  474.     dc.w    %0110011110001100
  475.     dc.w    %0001100001100000
  476.     dc.w    %0000110011001000
  477.     dc.w    %0000001100100000
  478.  
  479.  
  480. _ball5:
  481.     public    _ball5
  482.  
  483.     dc.w    %0000001100100000
  484.     dc.w    %0000110011001000
  485.     dc.w    %0001100011100100
  486.     dc.w    %0100111000011000
  487.     dc.w    %0101111000011100
  488.     dc.w    %1001111000001110
  489.     dc.w    %1110000111110001
  490.     dc.w    %1100000111110001
  491.     dc.w    %1100000111110001
  492.     dc.w    %1110000111110001
  493.     dc.w    %1001111000001110
  494.     dc.w    %0101111000011100
  495.     dc.w    %0101111000011000
  496.     dc.w    %0001100011100100
  497.     dc.w    %0000110011001000
  498.     dc.w    %0000001100100000
  499.  
  500. #endasm
  501.  
  502.  
  503.  
  504.  
  505.  
  506.